<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php');

/**
 * Razred filter form base class.
 *
 * @package    dnevnik
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
 */
class BaseRazredFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'skola_id'             => new sfWidgetFormPropelChoice(array('model' => 'Skola', 'add_empty' => true)),
      'smer_id'              => new sfWidgetFormPropelChoice(array('model' => 'Smer', 'add_empty' => true)),
      'profesor_id'          => new sfWidgetFormPropelChoice(array('model' => 'Profesor', 'add_empty' => true)),
      'razred'               => new sfWidgetFormFilterInput(),
      'slovo'                => new sfWidgetFormFilterInput(),
      'jezik'                => new sfWidgetFormPropelChoice(array('model' => 'Predmet', 'add_empty' => true)),
      'jezik_profesor'       => new sfWidgetFormPropelChoice(array('model' => 'Profesor', 'add_empty' => true)),
      'tip'                  => new sfWidgetFormFilterInput(),
      'operater_razred_list' => new sfWidgetFormPropelChoice(array('model' => 'Operater', 'add_empty' => true)),
      'ucenik_razred_list'   => new sfWidgetFormPropelChoice(array('model' => 'Ucenik', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'skola_id'             => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Skola', 'column' => 'id')),
      'smer_id'              => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Smer', 'column' => 'id')),
      'profesor_id'          => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Profesor', 'column' => 'id')),
      'razred'               => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'slovo'                => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'jezik'                => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Predmet', 'column' => 'id')),
      'jezik_profesor'       => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Profesor', 'column' => 'id')),
      'tip'                  => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'operater_razred_list' => new sfValidatorPropelChoice(array('model' => 'Operater', 'required' => false)),
      'ucenik_razred_list'   => new sfValidatorPropelChoice(array('model' => 'Ucenik', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('razred_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addOperaterRazredListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(OperaterRazredPeer::RAZRED_ID, RazredPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(OperaterRazredPeer::OPERATER_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(OperaterRazredPeer::OPERATER_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function addUcenikRazredListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(UcenikRazredPeer::RAZRED_ID, RazredPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(UcenikRazredPeer::UCENIK_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(UcenikRazredPeer::UCENIK_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Razred';
  }

  public function getFields()
  {
    return array(
      'id'                   => 'Number',
      'skola_id'             => 'ForeignKey',
      'smer_id'              => 'ForeignKey',
      'profesor_id'          => 'ForeignKey',
      'razred'               => 'Number',
      'slovo'                => 'Number',
      'jezik'                => 'ForeignKey',
      'jezik_profesor'       => 'ForeignKey',
      'tip'                  => 'Number',
      'operater_razred_list' => 'ManyKey',
      'ucenik_razred_list'   => 'ManyKey',
    );
  }
}
